package com.nontax.test.util;

import com.nontax.test.common.domain.StdRestParameter;
import org.apache.commons.codec.digest.DigestUtils;

import java.nio.charset.Charset;

public class StdRestSignUtil {

    public static String sign(StdRestParameter parameter) {
        if(parameter == null) {
            return "";
        }
        String str = "appid=" + parameter.getAppid() +
                "&data=" + parameter.getData() +
                "&noise=" + parameter.getNoise() +
                "&key=" + parameter.getAppkey() +
                "&version=" + parameter.getVersion();
        return DigestUtils.md5Hex(str.getBytes(Charset.forName("UTF-8"))).toUpperCase();
    }
}
